<template lang="html">
    <div class="box">
        <div class="header">
            <el-tabs v-model="activeName" @tab-click="switchTabBar()">
                <el-tab-pane label="维修厂" name="1"></el-tab-pane>
                <el-tab-pane label="运营商" name="2"></el-tab-pane>
            </el-tabs>
        </div>
        <div class="body">
              <!--  -->
              <div class="table_box" v-show="activeName==1">
                  <el-form class="filterCondition demo-form-inline" :inline="true" label-width="80px">
                      <el-input placeholder="输入维修厂名称或车主名称" v-model="keyword" style="width: 420px;">
                          <el-button slot="append" style="width: 120px;" @click="search(1)">搜索</el-button>
                      </el-input>
                      <el-form-item label="时间段" style="margin-bottom: 0;width: 520px;">
                          <el-date-picker v-model="intervalTime" type="daterange" align="right" unlink-panels range-separator="-"
                            start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
                            value-format="yyyy-MM-dd HH:mm:ss" >
                          </el-date-picker>
                      </el-form-item>
                  </el-form>
                  <el-table :data="tableData.list" style="width: 100%">
                      <el-table-column  prop="create_time" align="center" label="投诉时间" ></el-table-column>
                      <el-table-column  prop="name"  align="center" label="投诉者" ></el-table-column>
                      <el-table-column  prop="company"  align="center" label="被投诉者" ></el-table-column>
                      <!-- <el-table-column  prop="title"  align="center" label="投诉标题" ></el-table-column> -->
                      <el-table-column  prop="content"  align="center" label="投诉内容" ></el-table-column>
                  </el-table>
              </div>

              <div class="table_box" v-show="activeName==2">
                  <el-form class="filterCondition demo-form-inline" :inline="true" label-width="80px">
                      <el-input placeholder="输入维修厂名称或运营商名称" v-model="keyword" style="width: 420px;">
                          <el-button slot="append" style="width: 120px;" @click="search(1)">搜索</el-button>
                      </el-input>
                      <el-form-item label="时间段" style="margin-bottom: 0;width: 520px;">
                          <el-date-picker v-model="intervalTime" type="daterange" align="right" unlink-panels range-separator="-"
                            start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
                            value-format="yyyy-MM-dd HH:mm:ss" >
                          </el-date-picker>
                      </el-form-item>
                  </el-form>
                  <el-table :data="tableData.list" style="width: 100%">
                      <el-table-column  prop="create_time" align="center" label="投诉时间" ></el-table-column>
                      <el-table-column  prop="shop_name"  align="center" label="投诉者" ></el-table-column>
                      <el-table-column  prop="agent_name"  align="center" label="被投诉者" ></el-table-column>
                      <el-table-column  prop="title"  align="center" label="投诉标题" ></el-table-column>
                      <el-table-column  prop="content"  align="center" label="投诉内容" ></el-table-column>
                  </el-table>
              </div>

              <div class="page_box">
                  <el-pagination class="page" layout="prev, pager, next"
                    @current-change="changePage" :current-page="currentPage" :page-count='tableData.rows' >
                  </el-pagination>
              </div>

        </div>
    </div>
</template>

<script>
export default {
  data(){
    return {
      activeName: '1',
      currentActive:'1',
      keyword: '',
      intervalTime: [],
      tableData: [],
      currentPage:1
    }
  },
  created(){
    this.search()
  },
  methods:{
    initSetData(){
      this.keyword = ''
      this.tableData = []
      this.intervalTime = []
    },
    switchTabBar(){
      if(this.activeName == this.currentActive){
        return false;
      }else{
         this.currentActive = this.activeName
         this.initSetData()
         this.search()
      }
    },
    search(page){
      if(this.currentActive == 1){
        this.complainadminShop(page)
      }else{
        this.complainadminAgent(page)
      }
    },

    complainadminAgent(page = 1){
      this.currentPage = page;
      this.$http4.complainadminAgent({
        key: this.keyword,
        page: page,
        start_time: (this.intervalTime && this.intervalTime[0]) || '',
        end_time: (this.intervalTime && this.intervalTime[1]) || ''
      }).then(res=>{
        this.tableData = res.data.code == 1 ?
        res.data.data : []
      })
    },
    complainadminShop(page = 1){
      this.currentPage = page;
      this.$http4.complainadminShop({
        key: this.keyword,
        page: page,
        start_time: (this.intervalTime && this.intervalTime[0]) || '',
        end_time: (this.intervalTime && this.intervalTime[1]) || ''
      }).then(res=>{
        this.tableData = res.data.code == 1 ?
        res.data.data : []
      })
    },

    changePage(e){
      this.search(e)
    }

  }
}
</script>

<style lang="css" scoped>
@import "../../my-style/app.css";
/deep/ .el-input-group__append, .el-input-group__prepend{
  background-color: #3498E9;
  border: none;
  color: white;
}
.page_box{
  text-align: center;
}
</style>
